<?php
namespace app\index\model;

use think\Exception;
use think\facade\Request;
use think\Model;
use think\model\concern\SoftDelete;

class Address extends Model{
    protected $pk='id';
    use SoftDelete;
    protected $deleteTime = 'delete_time';
     public static function   addressListInfo($id){
         $list=Address::alias('a')->field('a.id,a.is_default,a.name,a.tel,a.address,c.name as sname,cc.name as cname,ccc.name as qname')
             ->where('uid','=',$id)
             ->join('ecm_china_city c','a.sheng=c.id')
             ->join('ecm_china_city cc','a.city=cc.id')
             ->join('ecm_china_city ccc','a.quyu=ccc.id')
             ->select()->toArray();
         return $list;
         }

          public static function   addressDelInfo($get){
                try{
                    $res=Address::destroy($get['id']);
                }catch (Exception $e){
                    $res=false;
                }
                  return $res;
              }

         public static function  addressAddInfo($post){
         try{
             $res=Address::insert($post);
         }catch (Exception $e){
             $res=false;
         }
            return $res;
         }

          public static function    addressEditInfo($param){
             if (Request::isPost()){
                try{
                    $res=Address::update($param);
                }catch (Exception $e){
                    $res=false;
                }
                return $res;
             }else{
                 $find=Address::alias('a')->field('a.*,c.name as sname,cc.name as cname,ccc.name as qname')
                       ->join('ecm_china_city c','a.sheng=c.id')
                     ->join('ecm_china_city cc','a.city=cc.id')
                     ->join('ecm_china_city ccc','a.quyu=ccc.id')->find($param['id'])->toArray();
                 return $find;
             }
          }

        public static function   addressOrderInfo($adminuser_id,$post){
         $res=Adminuser::alias('au')->field('au.id as uid,au.uname')->where('au.id','=',$adminuser_id)->find()->toArray();
            $list=\app\index\model\Address::alias('a')->
//                field('a.id,a.name,a.tel,c.name as sname,cc.name as cname,ccc.name as qname,a.address')->
            where('a.id','=',$post['dizhi'])
//                ->join('ecm_china_city c','a.sheng=c.id')
//                ->join('ecm_china_city cc','a.city=cc.id')
//                ->join('ecm_china_city ccc','a.quyu=ccc.id')
                ->find()->toArray();
                 return [$res,$list];

           }

}